<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>已发布文章列表页</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/public.css">
<script type="text/javascript" src="${contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/common.js"></script>
<style type="text/css">
	#ownedArticleList-tbody .titleTd{
		text-align: left;
	}
	#ownedArticleList-tbody .titleTd a{
		margin-left: 15px;
	}
</style>
</head>
<body>
	<div class="container">
		<div class="panel panel-default" id="ownedArticleList">
			<div class="panel-heading">已发布文章列表页</div>
			<div class="panel-body">
				<form class="form-inline" role="form">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">文章标题：</div>
							<input class="form-control" onkeydown="if(event.keyCode==13){return false;}" id="searchTitle" type="text" placeholder="文章的标题">
						</div>
					</div>
					<button type="button" id="searchBtn" class="btn btn-default">查询</button>
				</form>
			</div>
			<table class="table table-striped table-bordered">
				<thead>
					<tr>
						<th>序号</th>
						<th style="width: 40%">标题(点击编辑)</th>
						<th>发布时间</th>
						<th>发布人</th>
						<th>删除</th>
					</tr>
				</thead>
				<tbody id = "ownedArticleList-tbody"></tbody>
			</table>
			<ul class="pagination"></ul>
		</div>
	</div>
<script type="text/javascript">
	var searchTitle = "";
	$(document).ready(function () {
		ownedArticleList(1);
		$("#searchBtn").click(function () {
			searchTitle = $("#searchTitle").val();
			ownedArticleList(1);
		});
	});
	ownedArticleList = function (pageNum) {
		$.ajax({
			type: 'POST',
			url: '${contextPath}/security/ownedArticleList',
			data: {"title": searchTitle, "page": pageNum},
			dataType: 'json',
			success: function (data) {
				if (data.list == "") {
					$("#ownedArticleList-tbody").empty();
					$("#ownedArticleList-tbody").append("<tr class='text-danger'><td colspan='5'>无内容</td></tr>");
					var pageDom = $("#ownedArticleList .pagination");
					pageDom.empty();
				} else {
					$("#ownedArticleList-tbody").empty();
					$.each(data.list,function (i, item) {
						$("#ownedArticleList-tbody").append(
							"<tr>"+
								 "<td>" + (i + 1) + "</td>" + 
								 "<td class='titleTd'><a href='${contextPath}/security/editArticle?id=" + item.id + "' target='_blank'>" + item.articleTitle + "</a></td>" + 
								 "<td>" + item.createTime + "</td>" + 
								 "<td>" + item.createUsername + "</td>" + 
								 "<td><a href='javascript:deleteArticle(\""+item.id+"\")'>删除</a></td>" +
							"</tr>"
						);
	
					});
					var pageDom = $("#ownedArticleList .pagination");
					pageDom.empty();
					pucPageTotle = data.totlePage;
					page.creatPageHTML(pageNum, pucPageTotle, pageDom, "ownedArticleList");
					$("#ownedArticleList .pageGoBtn").click(function () {
						var pageNum = 0;
						pageNum = $("#ownedArticleList .pageGoText").val();
						if (pageNum != 0 && 0 < pageNum && pageNum < pucPageTotle + 1) {
							loadUnCompletePackList(pageNum);
						}
					});
				}
			}
		});
	};
	deleteArticle = function (id) {
		var conWin = confirm("确定要删除该文章吗？");
		if (conWin) {
			$.ajax({
				type: 'POST',
				url: '${contextPath}/security/changeDeleteStatus',
				data: {"id": id, "isDelete": 1},
				dataType: 'json',
				success: function (data) {
					if(data.replay==1){
						alert("文章删除成功!");
					}else{
						alert("文章删除失败,请联系系统维护人员!!");
					}
					
					ownedArticleList(1);
				}
			});
		}
	
	};
</script>
</body>
</html>
